Another joint effort with Gerhard. Quit pretending that we have microsecond
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 20 Jul 2013 02:16:28 +0000 (02:16 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 20 Jul 2013 02:16:28 +0000 (02:16 +0000)
support.  Be more honest and call it millisecond everywhere.  Remove more
explicit accesses to microseconds member.  Still not quite zero, but getting
closer and this is a good checkpoint.

git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4461 f51c46e8-681c-474f-0cfe-069cfd0219fb

19 files changed:
gpsbabel/cetus.cc
gpsbabel/csv_util.cc
gpsbabel/defs.h
gpsbabel/destinator.cc
gpsbabel/ggv_log.cc
gpsbabel/gopal.cc
gpsbabel/itracku.cc
gpsbabel/jtr.cc
gpsbabel/magproto.cc
gpsbabel/mapsend.cc
gpsbabel/navilink.cc
gpsbabel/nmea.cc
gpsbabel/ozi.cc
gpsbabel/sbn.cc
gpsbabel/src/core/datetime.h
gpsbabel/stmwpp.cc
gpsbabel/unicsv.cc
gpsbabel/vitosmt.cc
gpsbabel/vitovtt.cc

index 93bbb8e1019ad4d38669648daff1a745c8cd5b81..58f9fb03233ab7e16ec2170e39305b62070d3e40 100644 (file)
@@ -211,7 +211,7 @@ read_track_point(cetus_track_point_t* data, const time_t basetime)
   }
 
   wpt->SetCreationTime(basetime +
-                       ((data->hour & 0x1F) * 3600) + (data->min * 60) + data->sec, (int)data->dsec * 10000);
+                       ((data->hour & 0x1F) * 3600) + (data->min * 60) + data->sec, data->dsec * 10);
 
   return wpt;
 }
index 8368133e7441424bc94d02a93f2d6df1abd7a2b6..28185d6df878600a5a466360fca13d15d652470a 100644 (file)
@@ -1182,7 +1182,7 @@ xcsv_parse_val(const char* s, waypoint* wpt, const field_map_t* fmp,
     int s_len = strlen(s);
     if (s_len < 4) {
       /* less than 1 epochsecond, an unusual case */
-      wpt->SetCreationTime(0,(int) atoi(s) * 1000);
+      wpt->SetCreationTime(0,(int) atoi(s));
     } else {
       char buff[32];
       int off = s_len - 3;
@@ -1192,7 +1192,7 @@ xcsv_parse_val(const char* s, waypoint* wpt, const field_map_t* fmp,
       s += off;
       strncpy(buff, s, 3);
       buff[3] = '\0';
-      wpt->SetCreationTime(t, (int) MILLI_TO_MICRO(atoi(buff)));
+      wpt->SetCreationTime(t, atoi(buff));
     }
   }
   break;
@@ -1946,7 +1946,7 @@ xcsv_waypt_pr(const waypoint* wpt)
       char tbuf[24];
       writetime(tbuf, sizeof(tbuf), "%s", wpt->GetCreationTime(), false);
       char mbuf[32];
-      snprintf(mbuf, sizeof(mbuf), "%s%03d", tbuf, wpt->microseconds / 1000);
+      snprintf(mbuf, sizeof(mbuf), "%s%03d", tbuf, wpt->GetCreationTime().msec());
       writebuff(buff, "%s", mbuf);
     }
     break;
index bae38ef4c809b443b139e7915e3f5dde2d011391..d76bc974df4e2a5aa66e5000b9a6862fef16001b 100644 (file)
@@ -532,9 +532,9 @@ public:
   }
   void SetCreationTime(time_t t) { creation_time = t; 
   }
-  void SetCreationTime(time_t t, int us) {
-    creation_time = t; 
-    microseconds = us;
+  void SetCreationTime(time_t t, int ms) {
+    creation_time.setTime_t(t);
+    creation_time = creation_time.addMSecs(ms);
   }
   gpsbabel::DateTime creation_time;
   int microseconds;    /* Optional millionths of a second. */
index f56a0887534e4f5c8fc43b47b5ee9ae01b15a134..d35ac0c1a8e09479a41bd5c08753c160dbb28e8b 100644 (file)
@@ -332,8 +332,10 @@ destinator_read_trk(void)
 
     snprintf(buff, sizeof(buff), "%06d%.f", date, time);
     strptime(buff, "%d%m%y%H%M%S", &tm);
-    wpt->SetCreationTime(mkgmtime(&tm),
-                         ((int)time % 1000) * 1000);
+    int millisecs = (int) time % 1000;
+    wpt->SetCreationTime(mkgmtime(&tm), millisecs);
+// FIXME: this is papering over a problem somewhere...
+wpt->microseconds = millisecs * 1000;
 
     if (wpt->fix > 0) {
       wpt->fix = (fix_type)(wpt->fix + 1);
@@ -446,7 +448,7 @@ destinator_trkpt_disp(const waypoint* wpt)
     gbfputint32(date, fout);
 
     time = ((int)tm.tm_hour * 10000) + ((int)tm.tm_min * 100) + tm.tm_sec;
-    time = (time * 1000) + (wpt->microseconds / 1000);
+    time = (time * 1000) + (wpt->GetCreationTime().msec());
     gbfputflt(time, fout);
   } else {
     gbfputint32(0, fout);      /* Is this invalid ? */
index 5b385c54e8ab2707ec48d7a55b0f827357e0d990..04efd7da0213f6c99c1bed7d94f041089846a5a9 100644 (file)
@@ -139,7 +139,7 @@ ggv_log_read(void)
     wpt->longitude = xlon;
 
     WAYPT_SET(wpt, course, le_read16(&buf[16 + 0]));
-    int microseconds = 0;
+    int milliseconds = 0;
     if (ggv_log_ver == 10) {
       double secs;
 
@@ -152,7 +152,7 @@ ggv_log_read(void)
       tm.tm_min =     le_read16(&buf[16 + 16]);
       secs =          le_read_double(&buf[16 + 18]);
       tm.tm_sec = (int)secs;
-      microseconds = (secs - tm.tm_sec) * 1000000;
+      milliseconds = lround((secs - tm.tm_sec) * 1000.0);
     } else {
       wpt->altitude = le_read16(&buf[16 + 4]);
       wpt->sat = (unsigned char)buf[16 + 14];
@@ -179,7 +179,7 @@ ggv_log_read(void)
       tm.tm_year -= 1900;
       if (tm.tm_mon > 0) {
         tm.tm_mon--;
-        wpt->SetCreationTime(mkgmtime(&tm), microseconds);
+        wpt->SetCreationTime(mkgmtime(&tm), milliseconds);
       }
     }
 
@@ -238,7 +238,7 @@ ggv_log_track_head_cb(const route_head* trk)
       speed = waypt_speed(prev, wpt);
     }
     if (wpt->creation_time > 0) {
-      secs = (double)tm.tm_sec + ((double)wpt->microseconds / 1000000);
+      secs = (double)tm.tm_sec + (1000 * wpt->GetCreationTime().msec());
     }
 
     gbfputint16((gbint16) latint, fout);
index e66f4b36078ecb36133d1b2f26d22bccd47d57b9..d244341920a57c60b185a676a13760395157a5bd 100644 (file)
@@ -218,6 +218,9 @@ gopal_read(void)
       case  0: /* "-" */       /* unknown fields for the moment */
         sscanf(c, "%lu", &microsecs);
         wpt->SetCreationTime(microsecs / 1000000, microsecs % 1000000);
+// FIXME: this is totally papering over a problem where creation time is
+// being overwritten later.
+wpt->microseconds = microsecs % 1000000;
         break;
       case  1:                         /* Time UTC */
         sscanf(c,"%lf",&hmsd);
index 918abd72b1873631aaf7c66a85f4fe2041d77c5f..649061f31cc05816624717a47ecadc7fc84aeab9 100644 (file)
@@ -661,15 +661,13 @@ itracku_rt_init(const char* fname)
 static void
 nmea_set_waypoint_time(waypoint* wpt, struct tm* time, double fsec)
 {
-  //fractions are stored as ms
-  int us = MILLI_TO_MICRO(lround(1000*fsec));
   if (time->tm_year == 0) {
-    wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, us);
+    wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, lround(1000.0 * fsec));
     if (wpt->wpt_flags.fmt_use == 0) {
       wpt->wpt_flags.fmt_use = 1;
     }
   } else {
-    wpt->SetCreationTime(mkgmtime(time), us);
+    wpt->SetCreationTime(mkgmtime(time), lround(1000.0 * fsec));
     if (wpt->wpt_flags.fmt_use != 0) {
       wpt->wpt_flags.fmt_use = 0;
     }
index 583c6c8b70be417a0e78e35ea9e2f85e32470624..b4ec4d8d83b7d20eefb6445793d1517319fde715 100644 (file)
@@ -41,7 +41,7 @@ static gbfile* fin, *fout;
 static avltree_t* trkpts;
 
 static time_t
-jtr_parse_time(const char* str, struct tm* tm, int* micro)
+jtr_parse_time(const char* str, struct tm* tm, int* milli)
 {
   long int hms;
   char* dot;
@@ -54,8 +54,8 @@ jtr_parse_time(const char* str, struct tm* tm, int* micro)
     hms = hms / 100;
     tm->tm_hour = hms % 100;
 
-    if ((*dot == '.') && (micro != NULL)) {
-      *micro = atoi(dot + 1) * 10000;
+    if ((*dot == '.') && (milli != NULL)) {
+      *milli = atoi(dot + 1) * 10;
     }
 
     return mkgmtime(tm);
@@ -115,7 +115,7 @@ jtr_read(void)
     double lat, lon;
     float speed, course, mcourse, mvar, mdev;
     time_t time = 0;
-    int micros = 0;
+    int mills = 0;
     char buf[32];
     char mvardir, mdevdir;
 
@@ -148,7 +148,7 @@ jtr_read(void)
       case 0:
         break;         /* GEOTAG2 */
       case 1:
-        jtr_parse_time(str, &tm, &micros);
+        jtr_parse_time(str, &tm, &mills);
         break;
       case 2:
         valid = *str;
@@ -219,7 +219,7 @@ jtr_read(void)
 
     wpt->latitude = lat;
     wpt->longitude = lon;
-    wpt->SetCreationTime(time, micros);
+    wpt->SetCreationTime(time, mills);
     if (speed >= 0) {
       WAYPT_SET(wpt, speed, speed);
     }
index 984922bb9fd596876a107b4d974adf8d297314c5..d9bdd701f135f44379ab0ca04f1a7fec30c122ab 100644 (file)
@@ -993,7 +993,7 @@ mag_trkparse(char* trkmsg)
   dmy = dmy / 100;
   tm.tm_mday = dmy % 100;
 
-  waypt->SetCreationTime(mkgmtime(&tm), CENTI_TO_MICRO(fracsecs));
+  waypt->SetCreationTime(mkgmtime(&tm), 10.0 * fracsecs);
 
   if (latdir == 'S') {
     latdeg = -latdeg;
@@ -1449,7 +1449,7 @@ void mag_track_disp(const waypoint* waypointp)
             tm->tm_sec;
       date = tm->tm_mday * 10000 + tm->tm_mon * 100 +
              tm->tm_year;
-      fracsec = MICRO_TO_CENTI(waypointp->microseconds);
+      fracsec = lround(waypointp->GetCreationTime().msec()/10.0);
     }
   }
   if (!tm) {
index 8c40711de1f1cc52f88eedbd3354abe774c6c1e5..31c1b91e956e4be97172faed9ae5dd69cb3375b2 100644 (file)
@@ -18,6 +18,7 @@
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  */
 
+#include <math.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -223,7 +224,7 @@ mapsend_track_read(void)
     } else {
       centisecs = 0;
     }
-    wpt_tmp->SetCreationTime(t, CENTI_TO_MICRO(centisecs));
+    wpt_tmp->SetCreationTime(t, 10.0 * centisecs);
 
     track_add_wpt(track_head, wpt_tmp);
   }
@@ -514,7 +515,7 @@ void mapsend_track_disp(const waypoint* wpt)
 
   /* 0 centiseconds */
   if (trk_version >= 30) {
-    c = MICRO_TO_CENTI(wpt->microseconds);
+    c = lround(wpt->GetCreationTime().msec() / 10.0);
     gbfwrite(&c, 1, 1, mapsend_file_out);
   }
 }
index cba283ae96cc45bb84540c7cc8fdc46e7447d3d7..12c6a9557e3057db92cc77432671240d847b7ca1 100644 (file)
@@ -796,10 +796,10 @@ serial_write_route_end(const route_head* route)
 }
 
 static int
-decode_sbp_usec(const unsigned char* buffer)
+decode_sbp_msec(const unsigned char* buffer)
 {
   int msec = le_read16(buffer);
-  return (msec % 1000) * 1000;
+  return (msec % 1000);
 }
 
 static time_t
@@ -852,7 +852,7 @@ navilink_decode_logpoint(const unsigned char* buffer)
   waypt->hdop = ((unsigned char)buffer[0]) * 0.2f;
   waypt->sat = buffer[1];
   waypt->SetCreationTime(decode_sbp_datetime_packed(buffer + 4),
-                         decode_sbp_usec(buffer + 2));
+                         decode_sbp_msec(buffer + 2));
   decode_sbp_position(buffer + 12, waypt);
   WAYPT_SET(waypt, speed, le_read16(buffer + 24) * 0.01f);
   WAYPT_SET(waypt, course, le_read16(buffer + 26) * 0.01f);
index fb4020308229c2de9c4dde3e2478651db9eb86e7..85af2da42cb68f045c692b3f7b80e59790aaca23 100644 (file)
@@ -358,16 +358,14 @@ nmea_wr_deinit(void)
 static void
 nmea_set_waypoint_time(waypoint* wpt, struct tm* time, double fsec)
 {
-  //fractions are stored as ms
-  int us = MILLI_TO_MICRO(lround(1000*fsec));
   if (time->tm_year == 0) {
-    wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, us);
+    wpt->SetCreationTime(((((time_t)time->tm_hour * 60) + time->tm_min) * 60) + time->tm_sec, lround(1000.0 * fsec));
     if (wpt->wpt_flags.fmt_use == 0) {
       wpt->wpt_flags.fmt_use = 1;
       without_date++;
     }
   } else {
-    wpt->SetCreationTime(mkgmtime(time), us);
+    wpt->SetCreationTime(mkgmtime(time), lround(1000.0 * fsec));
     if (wpt->wpt_flags.fmt_use != 0) {
       wpt->wpt_flags.fmt_use = 0;
       without_date--;
@@ -1301,7 +1299,7 @@ nmea_trackpt_pr(const waypoint* wpt)
 
   if (opt_gprmc) {
     snprintf(obuf, sizeof(obuf), "GPRMC,%010.3f,%c,%08.3f,%c,%09.3f,%c,%.2f,%.2f,%06d,,",
-             (double) hms + (wpt->microseconds / 1000000.0),
+             (double) hms + (wpt->GetCreationTime().msec() / 1000.0),
              fix=='0' ? 'V' : 'A',
              fabs(lat), lat < 0 ? 'S' : 'N',
              fabs(lon), lon < 0 ? 'W' : 'E',
@@ -1320,7 +1318,7 @@ nmea_trackpt_pr(const waypoint* wpt)
   }
   if (opt_gpgga) {
     snprintf(obuf, sizeof(obuf), "GPGGA,%010.3f,%08.3f,%c,%09.3f,%c,%c,%02d,%.1f,%.3f,M,0.0,M,,",
-             (double) hms + (wpt->microseconds / 1000000.0),
+             (double) hms + (wpt->GetCreationTime().msec() / 1000.0),
              fabs(lat), lat < 0 ? 'S' : 'N',
              fabs(lon), lon < 0 ? 'W' : 'E',
              fix,
index 6dd4b7edf03088387f867f64b6f959233d0a5831..48cd0b23e0c24abac95411b77fc6fcc93103a8c8 100644 (file)
@@ -165,7 +165,7 @@ ozi_set_time_str(const char *str, waypoint *waypointp)
 
   if(ozi_time > DAYS_SINCE_1990) {
     waypointp->SetCreationTime((ozi_time - DAYS_SINCE_1990) * SECONDS_PER_DAY,
-                               lround(1000000.0 * (ozi_time - (int) ozi_time)));
+                               lround(1000.0 * (ozi_time - (int) ozi_time)));
   }
 }
 
index ea524db9da64816149d5cdd9f6d4d006cadfae07..35af7d63c7295f4ae7e08503fa58a187696175b2 100644 (file)
@@ -225,7 +225,7 @@ decode_sbn_datetime(const unsigned char *buffer, waypoint *waypt)
   tm.tm_mon = buffer[2] - 1;
   tm.tm_year = be_readu16(buffer) - 1900;
 
-  waypt->SetCreationTime(mkgmtime(&tm), (ms % 1000) * 1000);
+  waypt->SetCreationTime(mkgmtime(&tm), (ms % 1000));
 }
 
 static void
index cebb55b94657d5a2c3e4b86fef548d62b09fecc1..d7c535683ca5be617a42b55faadfb5bc15f457a1 100644 (file)
@@ -43,51 +43,40 @@ public:
     t_ = -1;
   }
 
-  DateTime(QDate date, QTime time) : QDateTime(date, time) { }
-  DateTime(QDateTime dt) : QDateTime(dt) { }
-
+  DateTime(QDate date, QTime time) : QDateTime(date, time) {}
+  DateTime(QDateTime dt) : QDateTime(dt) {}
 
   // Handle time_tm tm = wpt->creation_time;
-  operator const time_t() const  {
-    return this->toTime_t();
-  }
+  operator const time_t() const { return this->toTime_t(); }
 
   const time_t& operator=(const time_t& t) {
     this->setTime_t(t);
     return t;
   }
 
-  time_t operator-- (int)  {
+  time_t operator--(int) {
     setTime_t(toTime_t() - 1);
     return this->toTime_t();
   }
 
-  time_t operator++ (int)  {
+  time_t operator++(int) {
     setTime_t(toTime_t() + 1);
     return this->toTime_t();
   }
 
-  time_t operator+=(const time_t&t) {
-   setTime_t(toTime_t() + t);
+  time_t operator+=(const time_t& t) {
+    setTime_t(toTime_t() + t);
     return this->toTime_t();
   }
 
   // Handle       tm = *gmtime(&wpt->creation_time)  ...poorly.
-  inline const time_toperator&() {
+  inline const time_t *operator&() {
     t_ = this->toTime_t();
-//fprintf(stderr, "inline set time_t %d\n", t_);
     return &t_;
   }
 
-  // Before Qt, GPSBabel had a 'microseconds' which is excessive and
-  // not really supported in QDateTime.  Milliseconds is fine, but we
-  // provide these shims for code that used usecs.
-  void addUSecs(qint64 usecs) const {
-    this->addMSecs(usecs / 1000);
-  }
-  int usec() const {
-    return this->time().msec() * 1000;
-  }
+  // A convenience method to return the number of milliseconds (0-999).
+  int msec() const { return this->time().msec(); }
 
   // Integer form: YYMMDD
   int ymd() const {
@@ -104,10 +93,11 @@ public:
     QTime time(this->time());
     return time.hour() * 10000 + time.minute() * 100 + time.second();
   }
+
   // Qt 4.6 and under doesn't have msecsTo.  Fortunately, it's easy to
   // provide.  It's a 64-bit because if the times aren't on the same day,
   // the returned value can be quite large.
-  int64_t msecsTo(const QDateTimedt) {
+  int64_t msecsTo(const QDateTime &dt) {
     qint64 days = this->daysTo(dt);
     qint64 msecs = this->time().msecsTo(dt.time());
     return days * (1000 * 3600 * 24) + msecs;
@@ -124,9 +114,8 @@ public:
     }
     return this->toUTC().toString(format);
   }
 
- private:
+private:
   time_t t_;
 };
 
index 291266137687d777faf167c4c6b14eb02c39999f..30e9e9f6c52d5f2fa36adeb36bb8d1d979909844 100644 (file)
@@ -103,11 +103,10 @@ stmwpp_data_read(void)
 
     wpt = NULL;
     memset(&time, 0, sizeof(time));
-    int microseconds = 0;
+    int milliseconds = 0;
 
     while ((c = csv_lineparse(buff, ",", "", column++))) {
       int new_what;
-      int fracsec;
 
       buff = NULL;
 
@@ -152,11 +151,10 @@ stmwpp_data_read(void)
         break;
 
       case 6:
-        sscanf(c, "%d:%d:%d.%d", &time.tm_hour, &time.tm_min, &time.tm_sec, &fracsec);
-        microseconds = MILLI_TO_MICRO(fracsec);
+        sscanf(c, "%d:%d:%d.%d", &time.tm_hour, &time.tm_min, &time.tm_sec, &milliseconds);
         /* makes sense only for recorded trackpoints */
         if (what != STM_TRKPT) {
-          microseconds = 0;
+          milliseconds = 0;
         }
         break;
 
@@ -167,7 +165,7 @@ stmwpp_data_read(void)
     if (wpt != NULL) {
       time.tm_year -= 1900;
       time.tm_mon--;
-      wpt->SetCreationTime(mkgmtime(&time), microseconds);
+      wpt->SetCreationTime(mkgmtime(&time), milliseconds);
 
       switch (what) {
       case STM_WAYPT:
@@ -275,7 +273,7 @@ stmwpp_waypt_cb(const waypoint *wpt)
     gbfprintf(fout, ".%02d", 0);
     break;
   case STM_TRKPT:
-    gbfprintf(fout, ".%03d", MICRO_TO_MILLI(wpt->microseconds));
+    gbfprintf(fout, ".%03d", wpt->GetCreationTime().msec());
     break;
   }
   gbfprintf(fout, ",\r\n");
index 3086d1bd8580e00944991462a59e0a5626c2c1a8..f1d8c0e14fc349a37df50887f3e84f2d2cd31e2f 100644 (file)
@@ -429,7 +429,7 @@ unicsv_parse_time(const char *str, int *msec, time_t *date)
   ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec, &ms);
   is_fatal(ct < 5, MYNAME ": Could not parse time string (%s).\n", str);
   if (ct == 6) {
-    *msec = (ms * 1000000) + 0.5;
+    *msec = lround((ms * 1000000));
     if (*msec > 999999) {
       *msec = 0;
       sec++;
@@ -1192,7 +1192,7 @@ unicsv_parse_one_line(char *ibuf)
     }
 
     if (msec >= 0) {
-      wpt->microseconds = msec;
+      wpt->creation_time.addMSecs(msec);
     }
 
     if (opt_utc) {
index bee5e1f390536f2c4f94723b1fcdbdc7baab37c0..a7d46dcdcfcc5dfc9ff15a1ab6487a1824c3c57d 100644 (file)
@@ -168,8 +168,8 @@ vitosmt_read(void)
     tmStruct.tm_sec    =(int)floor(seconds);
     tmStruct.tm_isdst  =-1;
 
-    wpt_tmp->SetCreationTime(mkgmtime(&tmStruct),
-                             fmod(1000000*seconds+0.5,1000000));
+    double usec = fmod(1000000*seconds+0.5,1000000);
+    wpt_tmp->SetCreationTime(mkgmtime(&tmStruct),lround(usec/1000.0));
     wpt_tmp->shortname = (char*) xcalloc(16,1);
     snprintf(wpt_tmp->shortname, 15 , "WP%04d", ++serial);
 
index f486a6488df1e3d387e6c801a264efee073c83dc..a8eeae640c295579b422642488753a6a5ff65f4e 100644 (file)
@@ -26,6 +26,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
+#include <math.h>
 
 #define MYNAME "vitovtt"
 #include "defs.h"
@@ -68,7 +69,6 @@ vitovtt_read(void)
   double                       altitude                = 0;
   struct tm            tmStruct;
   int                          scaled_sec              = 0;
-  int                          microseconds    = 0;
   double                       speed                   = 0;
   int                          course                  = 0;
   int                          status                  = 0;
@@ -110,9 +110,8 @@ vitovtt_read(void)
     wpt_tmp->altitude  = altitude;
 
     tmStruct.tm_sec = scaled_sec / vitovtt_secondscale;
-    microseconds = (scaled_sec % vitovtt_secondscale) / vitovtt_microsecondscale;
-    wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), microseconds);
-
+    int microseconds = (scaled_sec % vitovtt_secondscale) / vitovtt_microsecondscale;
+    wpt_tmp->SetCreationTime(mkgmtime(&tmStruct), lround(microseconds/1000.0));
     /*
      * TODO: interpret speed, course, status
      */